import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * Test2
 */
@SuppressWarnings("unchecked")
public class Test2 {

  public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
    arrayList.addAll(Arrays.asList(1, 2, 3, 4, 5));
    // 直接打印集合
    System.out.println("直接打印集合");
    System.out.println(arrayList);
    // for循环
    System.out.println("普通for循环");
    for (int i = 0; i < arrayList.size(); i++) {
      System.out.println(arrayList.get(i));
    }
    // 增强for循环
    System.out.println("增强for循环");
    for (Object object : arrayList) {
      System.out.println(object);
    }
    // 迭代器
    System.out.println("迭代器");
    Iterator iterator = arrayList.iterator();
    while (iterator.hasNext()) {
      Object object = iterator.next();
      System.out.println(object);
    }
    // lambda表达式
    System.out.println("lambda表达式");
    arrayList.forEach((object) -> {
      System.out.println(object);
    });
    // 匿名内部类
    System.out.println("匿名内部类");
    arrayList.forEach(new Consumer() {
      @Override
      public void accept(Object t) {
        System.out.println(t);
      }
    });
  }
}